import React, { useRef, useState, useEffect } from "react";
import { Table } from "@douyinfe/semi-ui";
import {
  initScroll,
  getSize,
  getDatas,
  commonInfo,
  initColumns,
} from "./const";

export default function VirtualizedFixedDemo(props) {
  const { deepConfig } = props;
  let virtualizedListRef = useRef();
  const [scroll, setScroll] = useState({});
  const [virtualized, setVirtualized] = useState({});
  const [tableDatas, setTableDatas] = useState([]);

  commonInfo.virtualizedListRef = virtualizedListRef;
  commonInfo.deepConfig = deepConfig;

  useEffect(() => {
    // 获取数据
    // getDatas().then((res) => setTableDatas(res));
    // 处理滚动
    initScroll();
    // 拿到尺寸
    getSize().then((res) => {
      setScroll({ y: res.y, x: res.x });
      setVirtualized({ itemSize: res.itemSize });
    });
  }, []);

  return (
    <>
      <Table
        id="scroll-table"
        virtualized={virtualized}
        resizable={deepConfig.is_allocation}
        pagination={false}
        columns={initColumns()}
        dataSource={tableDatas}
        scroll={scroll}
        getVirtualizedListRef={(ref) => (virtualizedListRef = ref)}
      />
    </>
  );
}
